/**
 * 
 */

/**
 * @author zhongfang
 *
 */
public class MissingNumber {
    public static int missingNumber(int[] nums) {
        int sum=0;
        for(int n:nums){
            sum+=n;
        }
        int N=nums.length;
        return (N+1)*N/2-sum;
    }
    public static int missingNumber2(int[] nums) {
        int sum=0;
        for(int n:nums){
            sum^=n;
        }
        return sum;
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println(missingNumber(new int[]{0, 1, 3}));
		System.out.println(missingNumber2(new int[]{0, 1, 3,4}));;
	}

}
